package com.cskaoyan.controller.wechat;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.promotion.Topic;
import com.cskaoyan.service.TopicService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author dengww
 * @create 2020/5/5 0:24
 */
@RestController
@RequestMapping("wx/topic")
public class WxTopicController {
    @Autowired
    TopicService topicService;

    @GetMapping("list")
    public BaseRespVo getTopicList()  {
        List<Topic> list = topicService.queryTopicList4Wx();
        Map<String,Object> map = new HashMap<>();
        long total = PageInfo.of(list).getTotal();
        map.put("total",total);
        map.put("data",list);
        return new BaseRespVo<>(0, map, "成功");
    }

    @GetMapping("detail")
    public BaseRespVo getTopicDetail(Integer id) {
        Topic topic = topicService.queryTopicDetail4Wx(id);
        Map<String,Object> map = new HashMap<>();
        map.put("topic",topic);
        return new BaseRespVo<>(0, map, "成功");
    }

    @GetMapping("related")
    public BaseRespVo getTopicRelated(Integer id) {
        List<Topic> topic = topicService.queryTopicRelated4Wx(id);
        /*Map<String,Object> map = new HashMap<>();
        map.put("topic",topic);*/
        return new BaseRespVo<>(0, topic, "成功");
    }
}
